﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessClass.StateMachine.Core
{
    /// <summary>
    /// 表示连续的两个状态（无条件转换）
    /// </summary>
    /// <typeparam name="CrrT"></typeparam>
    /// <typeparam name="NextT"></typeparam>
    public class ContinueState<CrrT, NextT> : ISate<NextT>
    {
        ISate<CrrT> crr;
        ISate<NextT> next;
        Action<CrrT> firstFinishAction;
        public ContinueState(ISate<CrrT> cs, ISate<NextT> ns)
        {
            crr = cs;
            next = ns;
        }
        public ContinueState(ISate<CrrT> cs, Action<CrrT> firstFinishAction, ISate<NextT> ns)
        {
            crr = cs;
            this.firstFinishAction = firstFinishAction;
            next = ns;
        }

        public NextT Accept(Machine m)
        {
            var ret = m.Visit(crr);
            if (firstFinishAction != null)
            {
                firstFinishAction(ret);
            }
            return m.Visit(next);
        }

    }
}
